package com.jia.together.controller.front;

import com.jia.together.entity.Blog;
import com.jia.together.service.BlogService;
import com.jia.together.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/front/blog")
//@CrossOrigin
public class BlogFrontController {
    @Autowired
    private BlogService blogService;

    @GetMapping("/queryList")
    public R queryList(@RequestParam(required = false) String key,@RequestParam(required = false) String categoryId,@RequestParam Long pageNum,@RequestParam Long pageSize){
        Map<String,Object> map = blogService.queryList(key,categoryId,pageNum,pageSize);
        return R.ok().data(map);
    }
    @GetMapping("/info/{id}")
    public R info(@PathVariable String id){
        Blog blog = blogService.selectInfoById(id);
        return R.ok().data("data",blog);
    }
    @PostMapping("/publish")
    public R publish(@RequestBody Blog blog){
        blogService.save(blog);
        return R.ok();
    }

    @GetMapping("/clickBlog")
    public R clickBlog(@RequestParam String blogId,@RequestParam(required = false) String memberId){
        blogService.clickBlog(blogId,memberId);
        return R.ok();
    }
    @GetMapping("/collect")
    public R collect(@RequestParam String blogId,@RequestParam String memberId){
        blogService.collectBlog(blogId,memberId);
        return R.ok();
    }
}
